using System;
using System.Runtime.Serialization;
using MiniStock.Entities.Common;
using MiniStock.Entities.Stock.Events.Product;

namespace MiniStock.Entities.Stock.Events.Order
{
    [DataContract]
    public class CreateOrderEvent : OrderEventBase
    {
        [DataMember]
        public Guid CustomerId { get; set; }

        [DataMember]
        public Guid ProductId { get; set; }

        [DataMember]
        public Decimal Amount { get; set; }

        [DataMember]
        public DateTime? Deadline { get; set; }


        public override void ValidateFor(EntityBase entity, IEntityProvider provider)
        {
            base.ValidateFor(entity, provider);
            var item = (Stock.Order) entity;
        }

        public override void ApplyTo(EntityBase entity)
        {
            var item = (Stock.Order) entity;
            item.CustomerId = this.CustomerId;
            item.Id = this.Id;
            item.Items.Add(new OrderItem()
                               {
                                   Id = Guid.NewGuid(),
                                   Amount = this.Amount,
                                   ProductId = this.ProductId,
                               });
            item.OrderReceived = DateTime.UtcNow;
            item.OrderDeadline = Deadline;
        }
    }
}